#include"SLIST.h"
void SeqListInit(SeqList* psl)
{
	psl->arr =(SLDataType*) malloc(sizeof(SLDataType)*4);
	if (psl->arr == NULL)
	{
		perror("malloc failed");
		exit(-1);
	}
	psl->capicity = 4;
	psl->size = 0;
}
void SeqListDestory(SeqList* psl)
{
	free(psl->arr);
	psl->arr = NULL;
	psl->size = 0;
	psl->capicity = 0;
}
void CheckCapacity(SeqList* psl)
{
	
	if (psl->capicity == psl->size)
	{
		SLDataType* tmp = (SLDataType*)realloc(psl->arr, psl->capicity * 2 * (sizeof(SLDataType)));
		if (tmp == NULL)
		{
			perror("realloc failed");
			exit(-1);
		}
		psl->arr = tmp;
		psl->capicity *= 2;
	}
}
void SeqListPushBack(SeqList* psl, SLDataType x)
{
	CheckCapacity(psl);
	psl->arr[psl->size] = x;
	psl->size++;
}
void SeqListPrint(SeqList* psl)
{
	int i = 0;
	for (i = 0;i < psl->size;i++)
	{
		printf("%d", psl->arr[i]);
	}
	printf("\n");
}
void SeqListPopBack(SeqList* psl)
{
	assert(psl->size > 0);
	psl->size--;
}
void SeqListPushFront(SeqList* psl, SLDataType x)
{
	CheckCapacity(psl);
	int i = 0;
	for (i = psl->size-1;i >= 0;i--)
	{
		psl->arr[i+1] = psl->arr[i];
	}
	psl->arr[0] = x;
	psl->size++;
}
void SeqListPopFront(SeqList* psl)
{
	assert(psl->size > 0);
	int i = 0;
	for (i = 0;i < psl->size-1;i++)
	{
		psl->arr[i] = psl->arr[i + 1];
	}
	psl->size--;
}
int SeqListFind(SeqList* psl, SLDataType x)
{
	int i = 0;
	for (i = 0;i < psl->size;i++)
	{
		if (psl->arr[i] == x)
		{
			return i + 1;
		}
	}
	return 0;
}
void SeqListInsert(SeqList* psl, size_t pos, SLDataType x)
{
	CheckCapacity(psl);
	int i = 0;
	for (i = psl->size - 1;i >= pos-1;i--)
	{
		psl->arr[i + 1] = psl->arr[i];
	}
	psl->arr[pos-1] = x;
	psl->size++;
}
void SeqListErase(SeqList* psl, size_t pos)
{
	assert(psl->size > 0);
	int i = 0;
	for (i = pos-1;i < psl->size - 1;i++)
	{
		psl->arr[i] = psl->arr[i + 1];
	}
	psl->size--;
}





























































